/*
 * CS_SOCIAL_CONFIRM_FRIEND_REQ.cpp
 *
 *  Created on: 2013. 6. 4.
 *      Author: the2
 */


#include "../../Command.h"
#include "../../User.h"
#include "../../Proxy.h"
#include "../../../../protocol/iFriends.h"

namespace ProjectZ { namespace NCommand {

void Command::CS_SOCIAL_CONFIRM_FRIEND_REQ(User * pUser, ::Network::Packet * pPacket)
{
	PREPARE_PACKET;
	ConfirmFriendSyn msg;

	*pPacket >> msg.news_seq >> msg.gid;
	pPacket->ParseMsg("%c", &msg.is_accept);

	DEBUGLOG("news_seq=%d gid=%d is_accept=%d", msg.news_seq, msg.gid, msg.is_accept);
	if( msg.gid <= 0 )
	{
		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
		pAck->MsgCat("%2d%8d", ACK_UNKNOWN_ERROR, msg.news_seq);

		pAck->MakePacket(CMD_SC_SOCIAL_CONFIRM_FRIEND_REQ);
		pUser->Send(pAck);
		return;
	}

	if(1 != msg.is_accept)
	{
		::ProjectZ::NProxy::SendFriendsServer(pUser->GetUserSeq(), msg);
		FriendTypeModifySyn frmsg;
//		frmsg.socialid = pUser->GetSocialID().c_str();
		frmsg.socialid = atoll(pUser->GetSocialID().c_str());
		frmsg.gid = pUser->GetUserSeq();
		frmsg.type = 5; // 거절
		::ProjectZ::NProxy::SendFriendsServer(msg.gid, frmsg);
	}
	else
	{
		AllowFriendSyn allowmsg;
		allowmsg.seq = msg.gid;
		allowmsg.userseq = pUser->GetUserSeq();
		allowmsg.msgid = ConfirmFriendSyn::MSG_ID;
		allowmsg.dummy = msg.news_seq;

		::ProjectZ::NProxy::SendFriendsServer(allowmsg.seq, allowmsg);
	}
}

} /*NCommand*/ } /*ProjectZ*/

